<%--
  Created by IntelliJ IDEA.
  User: Hx162
  Date: 2021/9/23
  Time: 15:53
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>Title</title>
    <script src="js/jquery-1.8.3.min.js"></script>
</head>
<body>
<form>
    <input type="text" id="tel" placeholder="手机号">
    <span id="sp">请输入手机号</span>
    <br>
    <input type="password" placeholder="验证码"><br>
    <input type="submit" value="注册"><br>
</form>

<script>
    $("#tel").blur(function () {
        var tel = $("#tel").val();
        if (null == tel || "" == tel) {
            alert('手机号必填');
            return;
        }

    });
    $.ajax({
        url: "/checkTel",//请求服务端的路径
        type: "post",//请求方式
        dataType: "json",//返回数据的格式
        data: "phone=" + tel,//提交的参数
        success: function (obj) {//回调函数
            //obj接受返回的json数据
            if (obj.state == 200) {
                $("#sp").html(obj.msg);
                $("#sp").attr("style", "color:green");
                alert(obj);
            } else {
                $("#sp").html(obj.msg);
                $("#sp").attr("style", "color:red");
            }
        }
    });
</script>
</body>
</html>
